package com.pet.pet08diary.controller;

import com.pet.pojo.Diary;
import com.pet.service.DiaryService;
import com.pet.vo.PageResult;
import com.pet.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*  郑滔  */
@RestController
@RequestMapping("/diary")
public class DiaryController {
    @Autowired
    private DiaryService diaryService;


    @GetMapping("/getDiaryListAllPublic")
    public SysResult getDiaryListAllPublic(PageResult pageResult){
        pageResult = diaryService.getDiaryListAllPublic(pageResult);
        return SysResult.success(pageResult);
    }
    @GetMapping("/getDiaryById")
    public SysResult getDiaryById(Integer id){
        Diary diary = diaryService.getDiaryById(id);
        return SysResult.success(diary);
    }
    @PostMapping("/updateStatus/{id}/{status}")
    public SysResult updateStatus(Diary diary){
        diaryService.updateStatus(diary);
        return SysResult.success();
    }
    @PostMapping("/saveDiary")
    public SysResult saveDiary(@RequestBody Diary diary){
        System.out.println(diary);
        Integer id = diaryService.saveDiary(diary);
        return SysResult.success(id);
    }
    @PostMapping("/updateDiary")
    public SysResult updateDiary(@RequestBody Diary diary){
        diaryService.updateDiary(diary);
        return SysResult.success();
    }
    @DeleteMapping("/deleteDiaryById/{id}")
    public SysResult deleteDiaryById(@PathVariable String id){
        diaryService.deleteDiaryById(id);
        return SysResult.success();
    }

}
